package com.ruoyi.project.digital.controller.api;


import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.aspectj.lang.annotation.NoNeedAccess;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.digital.domain.*;
import com.ruoyi.project.digital.domain.dto.LoginWechatUser;
import com.ruoyi.project.digital.domain.vo.NoticeVo;
import com.ruoyi.project.digital.domain.vo.UserPetVo;
import com.ruoyi.project.digital.service.*;
import com.ruoyi.project.digital.service.impl.VoteServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;


@Api(value = "首页相关接口", tags = "首页相关接口")
@RestController
@RequestMapping("api/front/index")
public class IndexController extends BaseController {


    @Autowired
    private WechatUserTokenService wechatUserTokenService;
    @Autowired
    private ITUserService userService;
    @Autowired
    private IMoodService moodService;
    @Autowired
    private IPetService petService;
    @Autowired
    private IUserPetService userPetService;
    @Autowired
    private ITaskService taskService;
    @Autowired
    private INoticeService noticeService;
    @Autowired
    private IUserTaskService userTaskService;
    @Autowired
    private VoteServiceImpl voteService;
    @Autowired
    private ITBackService backService;

    @ApiOperation(value = "首页宠物列表")
    @GetMapping("/petList")
    private AjaxResult< List<UserPetVo>> getMyIndex() {
        LoginWechatUser loginMember = wechatUserTokenService.getLoginWechatUser(ServletUtils.getRequest());
        List<UserPetVo>  userPetList=  userPetService.frontList(loginMember.getId());

        return AjaxResult.success(userPetList);
    }


    @ApiOperation(value = "首页随机返回背景图")
    @GetMapping("/backRandom")
    private AjaxResult  backRandom() {
          TBack back=  backService.selectRandom();
        return AjaxResult.success(back);
    }

    @ApiOperation(value = "首页未读消息数量")
    @GetMapping("/noReadNumber")
    private AjaxResult noReadNumber() {
        LoginWechatUser loginMember = wechatUserTokenService.getLoginWechatUser(ServletUtils.getRequest());
        Integer number=  noticeService.noReadNumber(loginMember.getId());
        return AjaxResult.success(number);
    }


    @ApiOperation(value = "首页未读消息列表")
    @GetMapping("/noReadList")
    private AjaxResult noReadList() {
        LoginWechatUser loginMember = wechatUserTokenService.getLoginWechatUser(ServletUtils.getRequest());
        List<NoticeVo> number=  noticeService.noReadList(loginMember.getId());
        return AjaxResult.success(number);
    }

    @ApiOperation(value = "首页已读消息列表")
    @GetMapping("/readList")
    private AjaxResult readList() {
        LoginWechatUser loginMember = wechatUserTokenService.getLoginWechatUser(ServletUtils.getRequest());
        List<NoticeVo> number=  noticeService.readList(loginMember.getId());
        return AjaxResult.success(number);
    }


    @ApiOperation(value = "接受任务")
    @GetMapping("/acceptTask/{id}")
    private AjaxResult acceptTask(@PathVariable Long id) {
        LoginWechatUser loginMember = wechatUserTokenService.getLoginWechatUser(ServletUtils.getRequest());
        userTaskService.acceptTask(id,loginMember.getId());
        return AjaxResult.success();
    }


    @ApiOperation(value = "在线聊天")
    @GetMapping("/online/")
    private AjaxResult acceptTask() throws IOException {
        LoginWechatUser loginMember = wechatUserTokenService.getLoginWechatUser(ServletUtils.getRequest());
        voteService.updateVisitCount(loginMember.getOpenId());
        return AjaxResult.success();
    }
}
